package agents.utils;

import jade.core.AID;
import org.joda.time.DateTime;

/**
 * Represent a single order.
 * 
 * @author Group 6
 */
public class Order implements Comparable<Order>{
    
    public enum Priority {
        NORMAL,
        HIGH
    };
    
    // Variáveis e métodos de classe
    private static int numberOfOrders = 0;
    
    private static void increaseOrderNumber() {
        numberOfOrders++;
    }
    
    // Variáveis e métodos de instância
    private int id;
    private AID clientAID;
    private int qty;
    private int qtyFinished;
    private int priceByQty;
    private DateTime deadline;
    private Priority priority;

    public Order(AID clientAID, int qty, int priceByQty, DateTime deadline, Priority priority) {
        increaseOrderNumber();
        this.id = numberOfOrders;
        this.clientAID = clientAID;
        this.qty = qty;
        this.qtyFinished = 0;
        this.priceByQty = priceByQty;
        this.deadline = deadline;
        this.priority = priority;
    }

    public int getId() {
        return id;
    }

    public AID getClientAID() {
        return clientAID;
    }

    public int getQty() {
        return qty;
    }
    
    public void increaseFinishedQty() {
        this.qtyFinished++;
    }

    public int getQtyFinished() {
        return qtyFinished;
    }
    
    
    
    public void setFinished() {
        this.qtyFinished = this.qty;
    }

    public int getPriceByQty() {
        return priceByQty;
    }

    public DateTime getDeadline() {
        return deadline;
    }
    
    public boolean isFinished() {
        return (this.qty == this.qtyFinished) ? true : false;
    }

    public Priority getPriority() {
        return priority;
    }

    @Override
    public int compareTo(Order o) {
        return this.deadline.compareTo(o.getDeadline());
    }

    @Override
    public String toString() {
        
        
        float perCentFloat = (float) this.qtyFinished / this.qty;
        perCentFloat *= 100;
        int perCent = (int) perCentFloat;
        StringBuilder sb = new StringBuilder();
        sb.append("id:");
        sb.append(this.getId());
        sb.append(" | finished: ");
        sb.append(perCent);
        sb.append("%");
        return sb.toString();
    }
    
}